package com.i3q360.layui.common.base;

import java.text.ParseException;
import java.util.Map;

import org.apache.commons.lang3.time.DateUtils;

public class Format {
	
	
	public static String eq(String key){
		return " and "+key+"=:"+key;
	}

	public static String gte(String key) {
		return " and "+key+">=:"+key;
	}
    
	public static String lte(String key) {
		return " and "+key+"<=:"+key;
	}
    
	public static String commonFilter(String paramKey,Object paramValue,Map<String,Object> parameters){
		
		switch(paramKey){
			case "name":
				parameters.put(paramKey, paramValue);
				return Format.eq(paramKey);
			case "create_begin":
				try {
					parameters.put("createtime", DateUtils.parseDate(paramValue+"", "yyyy-MM-dd HH:mm:ss"));
				} catch (ParseException e) {
					e.printStackTrace();
				}
				return Format.gte("createtime");
			case "create_end":
				try {
					parameters.put("createtime", DateUtils.parseDate(paramValue+"", "yyyy-MM-dd HH:mm:ss"));
				} catch (ParseException e) {
					e.printStackTrace();
				}
				return Format.lte("createtime");
			default:
				return null;
		}
	}
	
}
